///////////////////////////////////////////////////////////////////////////////
//
//
//
///////////////////////////////////////////////////////////////////////////////

package model
{
    import flash.events.ErrorEvent;
    import flash.events.Event;

    import model.service.CurrencyRateService;
    import model.service.IElfinService;

    import model.vo.ConfigVO;


    /**
     *  CurrencyRateProxy store daily rates for currencies used by user.
     *  This proxy created on first rates retirvion.
     *
     *  CurrencyRatesProxy don't created for users which used only one currency.
     *
     *  @author: akolonitsky
     *  @date: 12/7/11 1:13 PM
     */
    public class CurrencyRatesProxy extends ElfinSafeProxy
    {
        public static const NAME:String = "currencyRatesProxy";

        public static const UPDATE:String = "currencyRatesUpdate";

        public function CurrencyRatesProxy(config:ConfigVO)
        {
            super(NAME, [], config);
        }

        public function getRates(currencies:Array=null, fromDate:Date = null, toDate:Date = null):void
        {
            var service:CurrencyRateService = createService(completeHandler);
            service.getCurrencyRates(currencies, fromDate, toDate);
        }



        //-------------------------------------------------------------------------
        //
        //  Private logic
        //
        //-------------------------------------------------------------------------

        private function createService(resultHandler:Function):CurrencyRateService
        {
            var serv:IElfinService = createElfinService(CurrencyRateService, resultHandler, errorHandler);
            return serv as CurrencyRateService;
        }

        private function completeHandler(event:Event):void
        {
            var service:CurrencyRateService = event.target as CurrencyRateService;
            sendNotification(UPDATE)
        }

        private function errorHandler(event:ErrorEvent):void
        {

        }


    }
}
